package cn.cmvideo.springboot.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import cn.cmvideo.springboot.handler.TimeHandler;

@Configuration
public class RouterConfig
{
	@Autowired
	private TimeHandler timeHandler;

	@Bean
	public RouterFunction<ServerResponse> timerRouter()
	{
		return RouterFunctions.route(RequestPredicates.GET("/time"), req -> timeHandler.getTime(req)) // lambda 箭头函数
				.andRoute(RequestPredicates.GET("/date"), timeHandler::getDate) // 方法引用
				.andRoute(RequestPredicates.GET("/times"), timeHandler::sendTimePerSec);
	}
}
